<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 李毅
  Date: 2023/8/18
  Time: 9:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<c:set var="path" value="${pageContext.request.contextPath }"/>
<html>
<head>
    <title>Title</title>
    <script src="${path}/js/jquery-3.6.4.js "></script>
<%--    <link href="${path}/css/lyCss/showComment.css" rel="stylesheet" type="text/css">--%>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        .b1{
            width: 70px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            display: inline-block;
            margin-left: 10px;
            background-color: #00cc9c;
            color: white;
            border-radius: 3px 3px 3px 3px;
            font-size: 12px;
            position: relative;
            top: 30px;
        }
        a{
            text-decoration: none;
        }
        .b2{
            background-color: white;
            position: relative;
            bottom: 21px;
            border-radius: 5px 5px 5px 5px;
        }
        img{
            width: 40px;
            height: 60px;
            display: inline-block;
        }
        table{
            border: 0px gainsboro;
            border-collapse: collapse;
            margin: 0px auto;
        }
        .a1{
            width: 150px;
            height: 80px;
            text-align: center;
        }
        .a2{
            width: 80px;
            text-align: center;
            color: #00cc9c;
        }
        .a3{
            width: 50px;
            text-align: center;
        }
        .a4{
            width: 550px;
        }
        .a5{
            text-align: center;
            width: 110px;
        }
        td{
            font-size: 12px;
        }
        .b3{
            width: 140px;
            height: 30px;
            border: 1px solid gainsboro;
            text-align: center;
            line-height: 30px;
            background-color: aliceblue;
            margin-left: 850px;
            margin-top:35px ;

        }
        .b4{
            width: 40px;
            height: 30px;
            font-size: 12px;
            background-color: #00cc9c;
            color: white;
            text-align: center;
            line-height: 30px;
            display: inline-block;
            margin-bottom: -11px;
            margin-left: 950px;
            position: relative;
            bottom: 30px;
            left: 40px;
        }
        .action .t{ height:41px; background:url(../../WEB-INF/images/backIndex/right_bg.gif) no-repeat; font:14px 宋体; padding:10px 0 0 30px;}
        form{
            display: inline-block;
        }
        .n1{
            width: 70px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            background-color: #00cc9c;
            color: white;
            border-radius: 3px 3px 3px 3px;
            font-size: 12px;
            display: inline-block;
            border: 0px;
        }
        .n2 {
            width: 30px;
            height: 30px;
        }
        .action .t{ height:41px; background:url(../../WEB-INF/images/backIndex/right_bg.gif) no-repeat; font:14px 宋体; padding:10px 0 0 30px;}

    </style>
</head>
<body>
    <div class="action  divaction">
        <div class="t">
            评论管理
        </div>
        <c:set var="commentList" value="${requestScope.commentList}"/>
        <div class="b2">
            <form method="post" action="${path}/CommentServlet?prom=showAll">
                <div>
                    <input type="text" placeholder="请输入电影名称" class="b3" name="movie_cn_name" value="${sessionScope.movie_name}">
                    <input type="submit" value="搜索" class="b4" style="border: 0px ">
                </div>
            </form>
            <table border="1">
                <tr>
                    <th>评论电影</th>
                    <th>评论者</th>
                    <th style="width: 80px;">评论点赞</th>
                    <th>评论内容</th>
                    <th style="width: 138px;">评论时间</th>
                    <th>操作</th>
                </tr>

                <c:choose>
                    <c:when test="${empty commentList}">
                        <script>
                            window.location="${path}/CommentServlet?prom=showAll";
                        </script>
                    </c:when>
                    <c:otherwise>
                        <c:forEach var="cl" items="${commentList}">
                            <tr id="${cl.comment_id}">
                                <td class="a1">${cl.movie_cn_name}</td>
                                <td class="a2">${cl.userName}</td>
                                <td class="a3">${cl.comment_good}</td>
                                <td class="a4">${cl.content}</td>
                                <td class="a5">${cl.comment_time}</td>
                                <td>
                                    <img src="${path}/images/tool/shanchu.jpg" class="n2" onclick="delMovie(${cl.comment_id})">
                                </td>
                            </tr>
                        </c:forEach>
                    </c:otherwise>
                </c:choose>
                <tr>
                <tr style="height: 50px;">
                    <th colspan="7" align="center">
                        <p style="display: inline-block">当前页数：[${sessionScope.pages.currPageNo}/${sessionScope.pages.totalPageCount}]
                            <c:if test="${sessionScope.pages.currPageNo>1}">
                        <form method="post" action="${path}/CommentServlet?prom=showAll&pageIndex=1&movie_cn_name=${sessionScope.movie_name}">
                            <input type="submit" value="首页" class="n1">
                        </form>
                        <form method="post" action="${path}/CommentServlet?prom=showAll&pageIndex=${sessionScope.pages.currPageNo-1}&movie_cn_name=${sessionScope.movie_name}">
                            <input type="submit" value="上一页" class="n1" >
                        </form>
                        </c:if>
                        <c:if test="${sessionScope.pages.currPageNo<sessionScope.pages.totalPageCount}">
                            <form method="post" action="${path}/CommentServlet?prom=showAll&pageIndex=${sessionScope.pages.currPageNo+1}&movie_cn_name=${sessionScope.movie_name}">
                                <input type="submit" value="下一页" class="n1">
                            </form>

                            <form method="post" action="${path}/CommentServlet?prom=showAll&pageIndex=${sessionScope.pages.totalPageCount}&movie_cn_name=${sessionScope.movie_name}">
                                <input type="submit" value="末页" class="n1">
                            </form>
                        </c:if>
                        </p>
                    </th>
                </tr>
            </table>
        </div>
    </div>
<script>
    function delMovie(id){
        var str=confirm("确认删除吗？");
        if (str){
            $.post("${path}/DelcommentServlet","&id="+id,function (result) {
                if(result>0){
                    alert("删除成功");
                    $("#"+id).remove(); //移除当前删除的行
                }else {
                    alert("删除失败");
                }
            });
        }
    }
</script>
</body>
</html>
